package yawning.mew.bear;

import yawning.mew.sim.SimulationEvent;

public class LotPEvent extends SimulationEvent {
	BearThreatSimulator mState;
	private boolean mHasLotP;
	private double mCooldownExpireTime;

	LotPEvent(BearThreatSimulator state) {
		super(state.mSimEngine);
		mState = state;

		mHasLotP = mState.mModel.mToon.getTalent(BearModel.LEADEROFTHEPACK) > 0;
	}

	void onTrigger() {
		if (mHasLotP) {
			if (mCooldownExpireTime < mState.mSimEngine.getSimTime()) {
				mNrLotPProcs++;

				double heal = mState.mModel.getHealth() * mState.mModel.multLotPHeal;

				if (mState.mIsLogging) mState.mLog.log("Leader of the Pack: ");

				if (mState.mSimEngine.getRandom().nextBoolean(mState.mModel.getHealCritChance())) {
					heal *= mState.mModel.multHealCrit;
					if (mState.mIsLogging) mState.mLog.logAppend("CRIT ");
				} else {
					if (mState.mIsLogging) mState.mLog.logAppend("HIT ");
				}

				heal *= mState.mFrenziedRegenerationAction.getMult();

				if (mState.mIsLogging) mState.mLog.logAppend("Heal: %d\n", Math.round(heal));

				mLotPHeal += Math.round(heal);

				mCooldownExpireTime = mState.mSimEngine.getSimTime() + mState.mModel.lotpCDDuration;
			}
		}
	}

	int mNrLotPProcs;
	long mLotPHeal;
}